<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/AdminTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="title">
        Category management
    </ui:define>

    <ui:define name="content">
         <h:form id="form">
            <p:growl id="growl" showDetail="true" life="3000" />
            <h:panelGrid columns="1">
                <h:panelGrid columns="1" >
                    <p:dataTable var="categoryvar" value="#{CategoryMBean.catelist}" rowKey="#{categoryvar.categoryID}" 
                                 selection="#{CategoryMBean.category}" selectionMode="single" filteredValue="#{CategoryMBean.filteredCategory}" id="categoryTable"
                                 paginator="true" rows="10"  
                                 paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
                                 rowsPerPageTemplate="5,10,15">
                        <p:ajax event="rowSelect" update=":form:display" oncomplete="cateDialog.show()" />

                        <f:facet name="header">
                            City Management
                        </f:facet>

                        <p:column headerText="City ID" style="width: 50%" sortBy="#{categoryvar.categoryID}" filterBy="#{categoryvar.categoryID}">
                            #{categoryvar.categoryID}
                        </p:column>

                        <p:column headerText="City Name" style="width: 50%" sortBy="#{categoryvar.categoryName}" filterBy="#{categoryvar.categoryName}">
                            #{categoryvar.categoryName}
                        </p:column>

                    </p:dataTable>

                    <p:dialog header="City Detail" widgetVar="cateDialog" resizable="false"  
                              width="350" showEffect="explode" hideEffect="explode">

                        <h:panelGrid id="display" columns="2" cellpadding="4">

                            <h:outputText value="City ID"/>
                            <h:inputText value="#{CategoryMBean.category.categoryID}" readonly="true"/>                        

                            <h:outputText value="City Name"/>
                            <h:inputText value="#{CategoryMBean.category.categoryName}" />

                            <p:commandButton value="Delete" action="#{CategoryMBean.removeCategory(CategoryMBean.category.categoryID)}" oncomplete="cateDialog.hide()" update=":form:categoryTable, :form:growl1"/>
                            <p:commandButton value="Update" action="#{CategoryMBean.editCategory(CategoryMBean.category)}" oncomplete="cateDialog.hide()" update=":form:categoryTable, :form:growl1"/>

                        </h:panelGrid>
                    </p:dialog>    

                </h:panelGrid>

            </h:panelGrid>

        </h:form>
        
        <h:form>
            <h:panelGrid columns="1">

                <p:commandButton id="viewButton" value="Add new City" 
                                 oncomplete="addCateDialog.show()"/> 

                <p:dialog id="dialogadd" header="Add New City" widgetVar="addCateDialog" resizable="false"  
                          showEffect="fade" hideEffect="fade">  
                    <h:panelGrid id="displayAdd" columns="2" cellpadding="4">  
                        <h:outputText value="City ID"/>
                        <p:inputText value="#{CategoryMBean.catenew.categoryID}" title="City ID" />                    

                        <h:outputText value="City Name" />
                        <p:inputText value="#{CategoryMBean.catenew.categoryName}" title="City Name"/>                    

                    </h:panelGrid>  
                    <p:commandButton value="Create" action="#{CategoryMBean.createCategory()}" oncomplete="addCateDialog.hide()" update=":form:growl1, :form:categoryTable" />                      

                </p:dialog>

            </h:panelGrid>
        </h:form>
    </ui:define>

</ui:composition> 
